package com.pr.config;

import feign.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author matengfei
 * @Date 2024/7/9 19:27
 * @PackageName:com.pr.config
 * @ClassName: FeignConfig
 * @Description: openfeign配置类
 * @Version 1.0
 */
@Configuration
@Slf4j
public class FeignConfig {

    /**
     * @Description: 设置RPC远程调用的超时时间
     * @param
     * @return feign.Request.Options
     */
    @Bean
    public Request.Options options(){
        // 连接时间5s 读取时间10s
        return new Request.Options(1000,1000);
    }

    @Bean
    public Retryer retryer(){
        return new Retryer.Default(3*1000,2*1000,5);
    }

    /**
     * @Description: 开启openfeign日志输出
     * @param
     * @return feign.Logger.Level
     */
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.BASIC; // 设置 Feign 的日志级别为 DEBUG
    }

    @Bean
    public RequestInterceptor requestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                log.info("feign 请求前添加请求头");
                requestTemplate.header("traceId","重试标识");
            }
        };
    }
}
